﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function() {
        gridList();
    });

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/Project/ExecuteWorkPlan/GetGridJsonAuto",
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "F_Id", hidden: true, key: true },
                {
                    label: '计划创建时间', name: 'F_CreatorTime', width: 180, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                {
                    label: '是否执行', name: 'IsExecute', width: 180, align: 'center',
                    cellattr: addCellAttr,
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "已执行" : "未执行";
                    }
                },
                {
                    label: '执行时间', name: 'ExecuteDateTime', width: 180, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                {
                    label: '是否回退', name: 'IsRollBack', width: 180, align: 'center',
                    cellattr: addCellAttr,
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "已回退" : "未回退";
                    }
                },
                {
                    label: '回退时间', name: 'RollbackTime', width: 180, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                }
            ],
            pager: "#gridPager",
            sortname: 'F_CreatorTime desc',
            viewrecords: true

        });
        $("#btn_search").click(function() {
            $gridList.jqGrid('setGridParam',
                {
                    postData: {
                        keyword: $("#txt_keyword").val(),
                        name: $("#txt_name").val()
                    },
                }).trigger('reloadGrid');
        });
    }

    function btn_delete() {
        $.deleteForm({
            url: "/Project/ExecuteWorkPlan/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        if (val == "已执行" || val =="已回退") {
            return "style='color:red'";
        } else {
            return "style='color:green'";
        }
       
    }

    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        console.log(window.location.href);
        $.modalOpen({
            id: "Details",
            title: "查看计划详情",
            url: "/Project/ExecuteWorkPlan/Details?keyValue=" + keyValue ,
            width: "700px",
            height: "700px",
            btn: null
        });
    }
    function btn_Executels() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalConfirm("注：您确定要执行计划操作吗？",
            function(r) {
                if (r) {
                    //var index = top.layer.getFrameIndex(window.name);
                   
                    $.ajax({
                        url: "/Project/ExecuteWorkPlan/ExecutePlan",
                        data: { keyValue: keyValue },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            debugger;
                            if (data.code >= 0) {
                                top.layer.closeAll('dialog');
                                //top.layer.close(1);
                                $.currentWindow().$("#gridList").resetSelection();
                                $.currentWindow().$("#gridList").trigger("reloadGrid");
                               

                            } else {

                                $.modalAlert(data.msg, "warning");
                                //window.setTimeout(top.layer.closeAll('dialog'),1000);
                                //$.currentWindow().$("#gridList").resetSelection();
                                //$.currentWindow().$("#gridList").trigger("reloadGrid");
                            }
                           
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $.loading(false);
                            $.modalMsg(errorThrown, "error");
                        },
                        beforeSend: function () {
                            $.loading(true, "正在执行");
                        },
                        complete: function () {
                            $.loading(false);
                        }
                    });
                
                   
                }
            });
    }
</script>


<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            @*<a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增股道</a>*@
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
               
                <li><a id="NF-Details" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看计划详情</a></li>
                <li><a id="NF-Executels" onclick="btn_Executels()"><i class="fa fa-search-plus"></i>直接执行计划</a></li>
                <li><a id="NF-delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除计划</a></li>
                <li class="split"></li>
                <a style="margin-left:59%; margin-top:-2%"class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group" style="padding-left:11px;padding-right:10px;">
                        @*<input id="txt_keyword" type="text" class="form-control" placeholder="按照课程名称模糊搜索" style="width: 200px; margin-right:20px;">*@
                        @*<select id="txt_state" class="form-control" style="width: 120px;margin-right:20px;" placeholder="按照状态搜索">
                                <option value="">请选择</option>
                                <option value="0">未审核</option>
                                <option value="1">审核驳回</option>
                                <option value="2">审核中</option>
                                <option value="3">审核通过</option>

                            </select>*@
                        @*<input id="txt_name" type="text" class="form-control" placeholder="按照场主名称模糊搜索" style="width: 200px; margin-right:20px;">
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary active"><i class="fa fa-search"></i></button>
                            </span>*@
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<style>
    table tr td {
        padding-left: 15px;
    }
</style>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
